//
//  SearchContentTableViewCellSecond.m
//  XYFMApp
//
//  Created by 岁变 on 16/9/10.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "SearchContentTableViewCellSecond.h"
#import "XYMacro.h"

@interface SearchContentTableViewCellSecond ()

@property (nonatomic, strong) UIView *redView;

@end

@implementation SearchContentTableViewCellSecond


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _redView = [[UIView alloc] init];
        _redView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_redView];
        
        _backImageView = [[UIImageView alloc] init];
        _backImageView.clipsToBounds = YES;
        [self.contentView addSubview:_backImageView];
        
        _frontImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"find_cat_cover"]];
        [self.contentView addSubview:_frontImageView];
        
        _bigBackImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"catinfo_item_bg"]];
        [self.contentView addSubview:_bigBackImageView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        [_bigBackImageView addSubview:_titleLabel];
        
        _fromLabel = [[UILabel alloc] init];
        _fromLabel.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _fromLabel.font = [UIFont systemFontOfSize:14];
        [_bigBackImageView addSubview:_fromLabel];
        
        _imageViewOne = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"catinfo_play_cnt"]];
        [_bigBackImageView addSubview:_imageViewOne];
        
        _imageViewTwo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_music_info1"]];
        [_bigBackImageView addSubview:_imageViewTwo];
        
        _imageViewThree = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"catinfo_time"]];
        [_bigBackImageView addSubview:_imageViewThree];
        
        _labelNumber = [[UILabel alloc] init];
        _labelNumber.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _labelNumber.font = [UIFont systemFontOfSize:14];
        [_bigBackImageView addSubview:_labelNumber];
        
        _labelGood = [[UILabel alloc] init];
        _labelGood.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _labelGood.font = [UIFont systemFontOfSize:14];
        [_bigBackImageView addSubview:_labelGood];
        
        _labelTime = [[UILabel alloc] init];
        _labelTime.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _labelTime.font = [UIFont systemFontOfSize:14];
        [_bigBackImageView addSubview:_labelTime];

    }
    return self;
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [_redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(50);
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.width.mas_offset(1);
        make.height.mas_offset(15);
    }];
    
    
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(18);
        make.top.equalTo(self.contentView.mas_top).with.offset(23);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-8);
        make.width.equalTo(_backImageView.mas_height);
    }];
    [_backImageView layoutIfNeeded];
    _backImageView.layer.cornerRadius = _backImageView.frame.size.height / 2;
    
    [_frontImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(10);
        make.top.equalTo(self.contentView.mas_top).with.offset(15);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.width.equalTo(_frontImageView.mas_height);
    }];
    
    [_bigBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_frontImageView.mas_right).with.offset(10);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.top.equalTo(self.contentView.mas_top).with.offset(15);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_bigBackImageView.mas_top).with.offset(5);
        make.left.equalTo(_bigBackImageView.mas_left).with.offset(40);
        make.right.equalTo(_bigBackImageView.mas_right).with.offset(-20);
        make.height.mas_offset(20);
    }];
    
    [_fromLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).with.offset(20);
        make.left.equalTo(_bigBackImageView.mas_left).with.offset(40);
        make.width.mas_offset(150);
        make.height.mas_offset(15);
    }];
    
    [_imageViewOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_fromLabel.mas_bottom).with.offset(5);
        make.left.equalTo(_bigBackImageView.mas_left).with.offset(40);
        make.width.mas_offset(10);
        make.height.mas_offset(10);
    }];
    
    [_labelNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imageViewOne.mas_right).with.offset(0);
        make.height.mas_offset(15);
        make.width.mas_offset(80);
        make.centerY.equalTo(_imageViewOne.mas_centerY);
    }];
    
    [_imageViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_labelNumber.mas_right).with.offset(0);
        make.height.mas_offset(10);
        make.width.mas_offset(10);
        make.centerY.equalTo(_labelNumber.mas_centerY);
    }];
    
    [_labelGood mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imageViewTwo.mas_right).with.offset(0);
        make.height.mas_offset(15);
        make.width.mas_offset(80);
        make.centerY.equalTo(_imageViewTwo.mas_centerY);
    }];
    
    [_imageViewThree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_labelGood.mas_right).with.offset(0);
        make.height.mas_offset(10);
        make.width.mas_offset(10);
        make.centerY.equalTo(_labelNumber.mas_centerY);
    }];
    
    [_labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imageViewThree.mas_right).with.offset(0);
        make.height.mas_offset(15);
        make.width.mas_offset(80);
        make.centerY.equalTo(_imageViewTwo.mas_centerY);
    }];
    
}

- (void)setModel:(SearchModelSecondData *)model {
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:model.music_img] placeholderImage:PLACEHOLDERIMAGE];
    _titleLabel.text = model.music_title;
    
    _fromLabel.text = [NSString stringWithFormat:@"by %@", model.music_user];
    _labelNumber.text = [NSString stringWithFormat:@"%ld", model.music_views];
    _labelGood.text = [NSString stringWithFormat:@"%ld", model.music_recomms];
    
    NSInteger min = model.music_duration / 60;
    NSInteger sec = model.music_duration % 60;
    _labelTime.text = [NSString stringWithFormat:@"%ld:%ld", min, sec];
}



@end
